//
//  Survey.m
//  Surveyer
//
//  Created by Qikun Guo on 13-8-19.
//  Copyright (c) 2013年 Tim. All rights reserved.
//

#import "Survey.h"
#import "Result.h"
#import "SurveyItem.h"


@implementation Survey

@dynamic intro;
@dynamic modifiedDate;
@dynamic title;
@dynamic showPageIndicator;
@dynamic time;
@dynamic items;
@dynamic result;

- (NSString *)textOutput
{
    NSString *string;
    NSString *lang = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
    if ([lang isEqualToString:@"zh-Hans"])
    {
        string = [NSString stringWithFormat:@"%@调查报告\n调查中共有%d项问题，取得%d项有效回答。具体情况如下：", self.title, self.items.count, self.result.count];
        int count = 0;
        for (SurveyItem *i in self.items)
        {
            count++;
            string = [string stringByAppendingFormat:@"\n问题%d：%@\n%@", count, i.title, [i textOutput]];
        }
    }
    else
    {
        string = [NSString stringWithFormat:@"For %d questions in the survey, there are %d valid responses.", self.items.count, self.result.count];
        int count = 0;
        for (SurveyItem *i in self.items)
        {
            count++;
            string = [string stringByAppendingFormat:@"\n\nQuestion %d：%@\n%@", count, i.title, [i textOutput]];
        }
    }
    string = [string stringByAppendingFormat:@"\n\n%@", NSLocalizedString(@"This survey report is generated by Surveyer", @"in the end of result sharing")];
    
    return string;
}
@end
